package com.neuedu.ylbx.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.neuedu.ylbx.pojo.DrugInfo;
import com.neuedu.ylbx.service.DrugInfoService;
import com.neuedu.ylbx.utils.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version V1.0
 * @author: xianzhen
 * @date: 2025/7/9
 */

@RestController
@RequestMapping("/drugInfo")
@Tag(name = "药品信息控制器")
@CrossOrigin
public class DrugInfoController {
    @Autowired
    private DrugInfoService drugInfoService;

    @GetMapping("/getDrugs")
    @Operation(summary = "获取药品列表")
    public ResultVo<List<DrugInfo>> getDrugs() throws Exception{
        return ResultVo.ok(drugInfoService.list());
    }

    @PostMapping("/addDrug")
    @Operation(summary = "添加药品")
    public ResultVo addDrug(DrugInfo drugInfo) throws Exception{
        drugInfoService.save(drugInfo);
        return ResultVo.ok("添加成功");
    }

    @PutMapping("/updateDrug")
    @Operation(summary = "修改药品信息")
    public ResultVo updateDrug(DrugInfo drugInfo) throws Exception{
        UpdateWrapper<DrugInfo> updateWrapper = new UpdateWrapper<DrugInfo>();
        updateWrapper.eq("id",drugInfo.getId());
        drugInfoService.update(drugInfo,updateWrapper);
        return ResultVo.ok("修改成功");
    }

    @DeleteMapping("/deleteDrug")
    @Operation(summary = "删除药品")
    public ResultVo deleteDrug(Integer drugID) throws Exception{
        drugInfoService.removeById(drugID);
        return ResultVo.ok("删除成功");
    }
}
